package cn.itcast.web.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/servletContextDemo5")
public class ServletContextDemo5 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /*
            3.获取文件的真实(服务器)路径
			    1.方法: String getRealPath(String path)
         */
        //1.通过HttpServlet对象获取
        ServletContext servletContext = request.getServletContext();
        //获取文件的真实(服务器)路径
        String a = servletContext.getRealPath("/a.txt");
        System.out.println(a);
        String b = servletContext.getRealPath("/WEB-INF/b.txt");
        System.out.println(b);
        String c = servletContext.getRealPath("/classes/c.txt");
        System.out.println(c);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
